package com.maiworld.seller.controller;

import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.maiworld.pojo.TbCoach;
import com.maiworld.pojo.TbConsume;
import com.maiworld.seller.service.ConsumeService;

import entity.PageResult;
import entity.Result;

@RestController
@RequestMapping("/con")
public class ConsumeController {

	@Reference
	private ConsumeService consumeService;
	
	@RequestMapping("/findAll")
	public List<TbConsume> findAll(){
		return consumeService.findAll();
	}
	
	@RequestMapping("/findPage")
	public PageResult findPage(int page, int rows){
		return consumeService.findPage(page, rows);
	}
	
	@RequestMapping("/add")
	public Result add(@RequestBody TbConsume consume){
		try{
			consumeService.add(consume);
			return new Result(true, "增加成功");
		}catch(Exception e ){
			e.printStackTrace();
			return new Result(false, "增加失败");
		}
	}
	
	@RequestMapping("/update")
	public Result update(@RequestBody TbConsume consume){
		try{
			consumeService.update(consume);
			return new Result(true, "修改成功");
			
		}catch(Exception e){
			e.printStackTrace();
			return new Result(false, "修改失败");
		}
	}
	
	@RequestMapping("/findOne")
	public TbConsume findOne( Long id){
		return consumeService.findOne(id);
	}
	
	@RequestMapping("/delete")
	public Result delete(Long[] ids){
		try{
			consumeService.delete(ids);
			return new Result(true, "删除成功");
		}catch(Exception e ){
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
	
	@RequestMapping("/search")	
	public PageResult search(@RequestBody TbConsume consume ,int page, int rows){
		return consumeService.findPageConsume(consume, page, rows);
	}
	
	
	
}
